package com.lzm.ydpt.module.riding.fragment;

import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.viewpager.widget.ViewPager;

import com.byt.framlib.base.BaseFragment;
import com.byt.framlib.base.TabFragmentAdapter;
import com.byt.framlib.basemvp.BasePresenter;
import com.byt.framlib.commonutils.DisplayUtil;
import com.byt.framlib.commonwidget.flycotab.SlidingTabLayout;
import com.byt.framlib.commonwidget.flycotab.listener.OnTabSelectListener;
import com.lzm.ydpt.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 骑手订单列表
 */
public class RidingOrderFragment extends BaseFragment {
    @BindView(R.id.rl_riding_order_title)
    RelativeLayout rl_riding_order_title;
    @BindView(R.id.tab_riding_order)
    SlidingTabLayout tab_riding_order;
    @BindView(R.id.vp_riding_order)
    ViewPager vp_riding_order;
    @BindView(R.id.tv_riding_order_num_most)
    TextView tv_riding_order_num_most;
    private static RidingOrderFragment sFragment;
    private List<String> detailList = new ArrayList<>();
    private ArrayList<BaseFragment> fragments = new ArrayList<>();

    public static RidingOrderFragment newsInstance() {
        sFragment = new RidingOrderFragment();
        return sFragment;
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.fragment_riding_order;
    }

    @Override
    public BasePresenter initPresenter() {
        return null;
    }

    @Override
    protected void initView() {
        detailList.clear();
        detailList.add("待取货");
        detailList.add("配送中");
        detailList.add("已完成");
        detailList.add("已取消");
        for (int i = 0, size = detailList.size(); i < size; i++) {
            fragments.add(RidingOrderListFragment.newsInstance(i));
        }
        vp_riding_order.setAdapter(new TabFragmentAdapter(getChildFragmentManager(), fragments, detailList));
        vp_riding_order.setOffscreenPageLimit(fragments.size());
        tab_riding_order.setTabWidthPx(fragments.size() > 4 ? DisplayUtil.getScreenWidth(context) / 4 : DisplayUtil.getScreenWidth(context) / fragments.size());
        tab_riding_order.setViewPager(vp_riding_order);
        tab_riding_order.setCurrentTab(0);
        tab_riding_order.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {

            }

            @Override
            public void onTabReselect(int position) {

            }
        });
    }

    @Override
    public void onDestroyView() {
        sFragment = null;
        super.onDestroyView();
    }
}
